﻿
Public Class ancestry ' the return val for ancestry functions
    Inherits sqlFunction


    Public Sub New(ByVal name As String)
        MyBase.new(name, sqlTable.itemTypes.fromFunction)

    End Sub


    Public network_id As Integer 'The id from the network table of the network that contains the relationship.
    Public ancestry_path As Integer 'When a concept appears in multiple places within a network, there will be a separate path for each occurrence. The ancestry_path identifies each separate path. It is an integer that starts from 0.
    Public depth As Integer 'The level from the root of the path. The root is always 0.
    Public from_namespace As String 'The namespace of the “from” element of the relationship.
    Public from_local_name As String 'The local name of the “from” element of the relationship.
    Public from_element_id As Integer 'The id from the element table of the “from” element of the relationship.
    Public to_namesapce As String 'The namespace of the “to” element of the relationship.
    Public to_local_name As String  'The local name of the “to” element of the relationship.
    Public to_element_id As Integer 'The id from the element table of the “to” element of the relationship.
    Public reln_order As Double 'The value of the “order” attribute on the arc for the relationship.
    Public calculation_weight As Double 'The value of the “weight” attribute on the arc for the relationship. This is null if there is no “weight” attribute.


    Public Overrides Sub fillFieldList()
        Dim mytype As Type = Me.GetType
        fields.Add("network_id", "The id from the network table of the network that contains the relationship.", mytype)
        fields.Add("ancestry_path", "When a concept appears in multiple places within a network, there will be a separate path for each occurrence. The ancestry_path identifies each separate path. It is an integer that starts from 0.", mytype)
        fields.Add("depth", "The level from the root of the path. The root is always 0.", mytype)
        fields.Add("from_namespace", "The namespace of the 'from' element of the relationship.", mytype)
        fields.Add("from_local_name", "The local name of the 'from' element of the relationship.", mytype)
        fields.Add("from_element_id", "The id from the element table of the 'from' element of the relationship.", mytype)
        fields.Add("to_namesapce", "The namespace of the 'to' element of the relationship.", mytype)
        fields.Add("to_local_name", "The local name of the 'to' element of the relationship.", mytype)
        fields.Add("to_element_id", "The id from the element table of the 'to' element of the relationship.", mytype)
        fields.Add("reln_order", "The value of the 'order' attribute on the arc for the relationship.", mytype)
        fields.Add("calculation_weight", "The value of the 'weight' attribute on the arc for the relationship. This is null if there is no 'weight' attribute.", mytype)

    End Sub

    Public Overrides Sub fillLinkTables()
        linkTables.Clear()
        linkTables.Add("network_id", "network", "network_id")
        linkTables.Add("from_element_id", "element", "element_id")
        linkTables.Add("to_element_id", "element", "element_id")
    End Sub


End Class


Public MustInherit Class sqlFunction
    Inherits sqlTable


    Public Sub New(ByVal fname As String, ByVal functionType As sqlTable.itemTypes)
        MyBase.New(fname, functionType)

        parametersLists = New List(Of functionParameters)

        setParams()
    End Sub

    Public Overridable Sub setParams()
    End Sub


    Public Overrides Function ToString() As String
        Dim s As String = ""

        Dim fo As Boolean = True

        For Each pl As functionParameters In parametersLists
            If Not fo Then s = s & " OR "
            fo = False
            s = s & "("

            Dim firstone As Boolean = True
            For Each p As functionParameter In pl
                If Not firstone Then s = s & ", "
                s = s & p.ToString
                firstone = False
            Next
            s = s & ")"
        Next

        If Len(s) = 0 Then s = "()"

        Return tableName & s
    End Function


    Public Shared Function getFunctionList() As sqlTables
        Dim l As New sqlTables

        l.Add(New distinct)
        l.Add(New ancestry_all)
        l.Add(New ancestry_compose_paths)
        l.Add(New ancestry_get_relationships)
        l.Add(New ancestry_in_accession)
        l.Add(New ancestry_in_network)
        l.Add(New hash_fact)
        l.Add(New extension_elment_id)
        l.Add(New hash_dimensional_qualifications)
        l.Add(New hash_dimensional_qualifications_for_fact)
        l.Add(New list_dimensional_qualifications)
        l.Add(New list_dimensional_qualifications_for_fact)
        l.Add(New fiscal_period)
        l.Add(New fiscal_year)
        l.Add(New fiscal_year_end)
        l.Add(New fiscal_year_beginning_of_year_adjustment)
        l.Add(New document_type)
        l.Add(New is_base)
        l.Add(New is_date)
        l.Add(New taxonomy_type)
        l.Add(New ticker)
        l.Add(New uom)



        Return l
    End Function

End Class

Public Class functionParameter
    Public name As String
    Public type As Type

    Public drawFromAField As Boolean = False
    Public drawFromFieldList As New List(Of drawfromfield)

    Public isOptional As Boolean = False


    Public description As String

    Public Sub New(ByVal name As String, ByVal type As Type, ByVal description As String)
        Me.name = name
        Me.type = type
        Me.description = description
    End Sub

    Public Overrides Function ToString() As String
        Return name
    End Function
End Class


Public Class functionParameters
    Inherits System.Collections.CollectionBase
  
    Public Sub Add(ByRef functionParameter As functionParameter)
        List.Add(functionParameter)
    End Sub




    Public Sub Remove(ByVal index As Integer)
        If index > Count - 1 Or index < 0 Then
        Else
            List.RemoveAt(index)
        End If
    End Sub

    Public Sub Remove(ByRef functionParameter As functionParameter)
        List.RemoveAt(Me.List.IndexOf(functionParameter))
    End Sub

    Public ReadOnly Property Item(ByVal index As Integer) As functionParameter
        Get
            Return CType(List.Item(index), functionParameter)
        End Get
    End Property

    Public ReadOnly Property ItemByID(ByVal ID As Integer) As functionParameter
        Get
            For Each itm In List
                If itm.id = ID Then
                    Return itm
                    Exit For
                End If
            Next
            Return Nothing
        End Get
    End Property
End Class



Public Class drawFromField
    Public fieldname As String
    Public tableName As String
    Public Sub New(ByVal fieldName As String, ByVal tableName As String)
        Me.fieldname = fieldName
        Me.tableName = tableName
    End Sub

End Class





Public Class distinct
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("distinct", sqlTable.itemTypes.selectFunction)
        tableDescription = ""
    End Sub


    'parameters:
    Public Overrides Sub setParams()
        Dim params As New functionParameters
        Dim param As New functionParameter("any", GetType(String), "")
     
        params.Add(param)


        Me.parametersLists.Add(params)


    End Sub
End Class


'ancestry functions

Public Class ancestry_all
    Inherits ancestry

    Public Sub New()
        MyBase.new("ancestry_all")
        tableDescription = "This function will search all networks from all filings (accessions) where the specified seed concept appears."
    End Sub


    'parameters:
    Public Overrides Sub setParams()
        Dim params As New functionParameters
        Dim param As New functionParameter("seed_id", GetType(Integer), "The element_id (from the element table) of the seed concept.")
        param.drawFromAField = True
        param.drawFromFieldList.Add(New drawFromField("element_id", "element"))
        params.Add(param)
        Me.parametersLists.Add(params)

        'now again for the overload 

        params = New functionParameters
        param = New functionParameter("seed_name", GetType(String), "The local name of the seed concept. Since only the local name is used to identify the seed concept, the result may contain ancestry paths for different concepts which have the same local name, but different namespaces. This happens with concepts in different versions of the same taxonomy (i.e. US GAAP 2009 and US GAAP 2011 or different filings for the same entity where the namespace of the extension concepts changes) and where the same local name may be used by different extension taxonomies (i.e. 2 different entities happen to use the same local name).")
        param.drawFromAField = False
        params.Add(param)
        Me.parametersLists.Add(params)

    End Sub

End Class



Public Class ancestry_in_accession
    Inherits ancestry

    Public Sub New()
        MyBase.new("ancestry_in_accession")
        tableDescription = "This function will search all networks from a specified filing (accession) where the specified seed concept appears."
    End Sub


    'parameters:
    Public Overrides Sub setParams()
        Dim params As New functionParameters
        Dim param As New functionParameter("accession_id", GetType(Integer), "The id of the filing (accession) (from the accession table) to search")
        param.drawFromAField = True
        param.drawFromFieldList.Add(New drawFromField("accession_id", "accession"))
        params.Add(param)

        Dim param2 As New functionParameter("seed_id", GetType(Integer), "The element_id (from the element table) of the seed concept.")
        param2.drawFromAField = True
        param2.drawFromFieldList.Add(New drawFromField("element_id", "element"))
        params.Add(param2)

        Me.parametersLists.Add(params)


        'now again for the overload 
        params = New functionParameters
        param = New functionParameter("accession_id", GetType(Integer), "The id of the filing (accession) (from the accession table) to search")
        param.drawFromAField = True
        param.drawFromFieldList.Add(New drawFromField("accession_id", "accession"))
        params.Add(param)

        param2 = New functionParameter("seed_name", GetType(String), "The local name of the seed concept. Since only the local name is used to identify the seed concept, the result may contain ancestry paths for different concepts which have the same local name, but different namespaces. Since this function scopes the search to a particular filing (accession), this would generally only occur if the extension taxonomy defined a concept with the same local name as a concept in the US GAAP taxonomies.")
        param2.drawFromAField = False
        params.Add(param2)

        Me.parametersLists.Add(params)


    End Sub

End Class

Public Class ancestry_in_network
    Inherits ancestry

    Public Sub New()
        MyBase.new("ancestry_in_network")
        tableDescription = "This function will search a specified network where the specified seed concept appears."
    End Sub


    'parameters:
    Public Overrides Sub setParams()
        Dim params As New functionParameters
        Dim param As New functionParameter("network_id", GetType(Integer), "The id of the network (from the network table) to search")
        param.drawFromAField = True
        param.drawFromFieldList.Add(New drawFromField("network_id", "network"))
        params.Add(param)

        Dim param2 As New functionParameter("seed_id", GetType(Integer), "The element_id (from the element table) of the seed concept.")
        param2.drawFromAField = True
        param2.drawFromFieldList.Add(New drawFromField("element_id", "element"))
        params.Add(param2)

        Me.parametersLists.Add(params)


        'now again for the overload 
        params = New functionParameters
        param = New functionParameter("network_id", GetType(Integer), "The id of the network (from the network table) to search")
        param.drawFromAField = True
        param.drawFromFieldList.Add(New drawFromField("network_id", "network"))  ' i think this is wrong in the document...says accession_ID
        params.Add(param)

        param2 = New functionParameter("seed_name", GetType(String), "The local name of the seed concept. Since only the local name is used to identify the seed concept, the result may contain ancestry paths for different concepts which have the same local name, but different namespaces. Since this function scopes the search to a particular filing (accession), this would generally only occur if the extension taxonomy defined a concept with the same local name as a concept in the US GAAP taxonomies.")
        param2.drawFromAField = False
        params.Add(param2)

        Me.parametersLists.Add(params)


    End Sub

End Class


Public Class ancestry_compose_paths
    Inherits ancestry

    Public Sub New()
        MyBase.new("ancestry_compose_paths")
        tableDescription = "This function returns the ancestry path from a specific relationship. This is a recursive function and will descend the network of relationships until it reaches bottom. This function is used by the other ancestry functions."
    End Sub


    'parameters:
    Public Overrides Sub setParams()
        Dim params As New functionParameters
        Dim param As New functionParameter("relationship_id", GetType(Integer), "The id of the relationship (from the relationship table) to search")
        param.drawFromAField = True
        param.drawFromFieldList.Add(New drawFromField("relationship_id", "relationship"))
        params.Add(param)

        Dim param2 As New functionParameter("depth", GetType(Integer), "This is the current depth starting from the initial relationship. This parameter is incremented on the recursive call. The default value is 0.")
        param2.drawFromAField = False
        'param2.drawFromFieldList.Add(New drawFromField("element_id", "element"))
        params.Add(param2)

        Me.parametersLists.Add(params)



    End Sub

End Class


Public Class ancestry_get_relationships
    Inherits ancestry

    Public Sub New()
        MyBase.new("ancestry_get_relationships")
        tableDescription = "This function finds all the relationships in a specified network starting from a specified seed concept and descending to the bottom of the network. This is a recursive function. This function is used by the other ancestry functions."
    End Sub


    'parameters:
    Public Overrides Sub setParams()
        Dim params As New functionParameters
        Dim param As New functionParameter("network_id", GetType(Integer), "The id of the network (from the network table) to search")
        param.drawFromAField = True
        param.drawFromFieldList.Add(New drawFromField("network_id", "network"))
        params.Add(param)

        Dim param2 As New functionParameter("seed_id", GetType(Integer), "The element_id (from the element table) of the seed concept.")
        param2.drawFromAField = True
        param2.drawFromFieldList.Add(New drawFromField("element_id", "element"))
        params.Add(param2)

        Me.parametersLists.Add(params)


    End Sub

End Class



'fact hashing


Public Class hash_fact
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("hash_fact", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function calculates the hash for a fact identified by its id."
    End Sub


    'parameters:
    Public Overrides Sub setParams()
        Dim params As New functionParameters
        Dim param As New functionParameter("fact_id", GetType(Integer), "The id of the fact (from the fact table).")
        param.drawFromAField = True
        param.drawFromFieldList.Add(New drawFromField("fact_id", "fact"))
        params.Add(param)


        Me.parametersLists.Add(params)


    End Sub

End Class



Public Class extension_elment_id
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("extension_elment_id", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns the element id of the first occurrence of an extension concept identified by the supplied local name and in the entity identified by the supplied entity id. The namespace of extension concepts change from filing to filing for an entity. If the local name is not used by the entity in any filing as an extension element, then null is returned." & vbCrLf & "This function is used by the hash_fact (integer) function and the hash_dimensional_qualifications (integer) function when creating a fact hash."
    End Sub


    'parameters:
    Public Overrides Sub setParams()
        Dim params As New functionParameters

        Dim p1 As New functionParameter("entity_id", GetType(Integer), "The id of the entity (from the entity table).")
        p1.drawFromAField = True
        p1.drawFromFieldList.Add(New drawFromField("entity_id", "entity"))
        params.Add(p1)

        Dim p2 As New functionParameter("local_name", GetType(String), "The local name of the extension concept.")
        params.Add(p2)

        Me.parametersLists.Add(params)

    End Sub


End Class


Public Class hash_dimensional_qualifications
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("hash_dimensional_qualifications", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function calculates the portion of the hash based on the dimensional qualifications associated with a context identified by its id. This function is used by hash_fact (integer)."
    End Sub

    'parameters:
    Public Overrides Sub setParams()

        Dim params As New functionParameters

        Dim p1 As New functionParameter("context_id", GetType(Integer), "The id of the context (from the context table).")
        p1.drawFromAField = True
        p1.drawFromFieldList.Add(New drawFromField("context_id", "context"))
        params.Add(p1)
        Me.parametersLists.Add(params)

        ' overload

        params = New functionParameters

        p1 = New functionParameter("context", GetType(context), "The context row of the context (from the context table).")
        params.Add(p1)
        Me.parametersLists.Add(params)
    End Sub

End Class

Public Class hash_dimensional_qualifications_for_fact
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("hash_dimensional_qualifications_for_fact", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns the dimensional qualifications identified by the QNames of the dimension concept and the member concept based on a fact identified by its id. This function returns the same character varying array as the list_dimensional_qualifications (integer) function but returns the dimensional qualifications based on a fact instead of a context."
    End Sub

    Public Overrides Sub setParams()

        Dim params As New functionParameters
        Dim p1 As New functionParameter("fact_id", GetType(Integer), "The id of the fact (from the fact table).")
        p1.drawFromAField = True
        p1.drawFromFieldList.Add(New drawFromField("fact_id", "fact"))
        params.Add(p1)
        Me.parametersLists.Add(params)
    End Sub
End Class



Public Class list_dimensional_qualifications
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("list_dimensional_qualifications", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns the dimensional qualifications identified by the QNames of the dimension concept and the member concept based on a context identified by its id. This isn’t a hash function, but it returns the same information that the hash_dimensional_qualifications (integer) function returns, but in a different format."
    End Sub

    'parameters:
    Public Overrides Sub setParams()

        Dim params As New functionParameters

        Dim p1 As New functionParameter("context_id", GetType(Integer), "The id of the context (from the context table).")
        p1.drawFromAField = True
        p1.drawFromFieldList.Add(New drawFromField("context_id", "context"))
        params.Add(p1)
        Me.parametersLists.Add(params)

    End Sub

End Class

Public Class list_dimensional_qualifications_for_fact
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("list_dimensional_qualifications_for_fact", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns the dimensional qualifications identified by the QNames of the dimension concept and the member concept based on a fact identified by its id. This function returns the same character varying array as the list_dimensional_qualifications (integer) function but returns the dimensional qualifications based on a fact instead of a context."
    End Sub

    Public Overrides Sub setParams()

        Dim params As New functionParameters
        Dim p1 As New functionParameter("fact_id", GetType(Integer), "The id of the fact (from the fact table).")
        p1.drawFromAField = True
        p1.drawFromFieldList.Add(New drawFromField("fact_id", "fact"))
        params.Add(p1)
        Me.parametersLists.Add(params)
    End Sub
End Class


'fiscal functions
Public Class fiscal_period
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("fiscal_period", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns the fiscal period for an instant period and the month and day of the fiscal year end." & vbCrLf & "The fiscal year end is determined by using the date with the supplied month and day that follows the supplied instant date. If the month and day supplied are the same or after the month and day of the instant, the year of the instant is used to form the fiscal year end. If the month and day supplied are before the month and day of the instant, the year of the instant plus one is used to form the fiscal year end."
    End Sub

    Public Overrides Sub setParams()

        Dim params As New functionParameters

        Dim p1 As New functionParameter("instant", GetType(Date), "The instant date to convert to a fiscal period.")
        '        p1.drawFromAField = True
        '       p1.drawFromFieldList.Add(New drawFromField("fact_id", "fact"))
        params.Add(p1)
        Dim p2 As New functionParameter("fiscal_end_month", GetType(Integer), "The month number for the fiscal year end.")
        params.Add(p2)
        Dim p3 As New functionParameter("fiscal_end_day", GetType(Integer), "The day number for the fiscal year end.")
        params.Add(p3)
        Me.parametersLists.Add(params)


        ' overload1

        params = New functionParameters

        p1 = New functionParameter("start_date", GetType(Date), "The start date of the duration to convert to a fiscal period.")
        params.Add(p1)

        p2 = New functionParameter("end_date", GetType(Date), "The end date of the duration to convert to a fiscal period.")
        params.Add(p2)

        p3 = New functionParameter("fiscal_end_month", GetType(Integer), "The month number for the fiscal year end.")
        params.Add(p3)
        Dim p4 As New functionParameter("fiscal_end_day", GetType(Integer), "The day number for the fiscal year end.")
        params.Add(p4)
        Me.parametersLists.Add(params)



        ' overload2

        params = New functionParameters

        p1 = New functionParameter("instant", GetType(Date), "The instant date to convert to a fiscal period.")
        params.Add(p1)

        p2 = New functionParameter("fiscal_year_end", GetType(Date), "The date of the fiscal year end.")
        params.Add(p2)
        Me.parametersLists.Add(params)


        ' overload3

        params = New functionParameters

        params.Add(New functionParameter("start_date", GetType(Date), "The start date of the duration to convert to a fiscal period."))
        params.Add(New functionParameter("end_date", GetType(Date), "The end date of the duration to convert to a fiscal period."))

        p3 = New functionParameter("fiscal_year_end", GetType(Date), "The date of the fiscal year end.")
        params.Add(p3)
        Me.parametersLists.Add(params)

        ' overload4

        params = New functionParameters

        params.Add(New functionParameter("instant", GetType(Date), "The instant date to convert to a fiscal period."))

        p2 = New functionParameter("accession_id", GetType(Integer), "The id of the filing (accession) (from the accession table) to search")
        p2.drawFromAField = True
        p2.drawFromFieldList.Add(New drawFromField("accession_id", "accession"))
        params.Add(p2)
        Me.parametersLists.Add(params)

        ' overload5
        params = New functionParameters

        params.Add(New functionParameter("start_date", GetType(Date), "The start date of the duration to convert to a fiscal period."))
        params.Add(New functionParameter("end_date", GetType(Date), "The end date of the duration to convert to a fiscal period."))

        p3 = New functionParameter("accession_id", GetType(Integer), "The id of the filing (accession) (from the accession table) to search")
        p3.drawFromAField = True
        p3.drawFromFieldList.Add(New drawFromField("accession_id", "accession"))
        params.Add(p3)

        Me.parametersLists.Add(params)


        ' overload6
        params = New functionParameters
        params.Add(New functionParameter("instant", GetType(Date), "The instant date to convert to a fiscal period."))

        params.Add(New functionParameter("context", GetType(context), "The context row of the context (from the context table)."))

        Me.parametersLists.Add(params)

        ' overload7
        params = New functionParameters
        params.Add(New functionParameter("start_date", GetType(Date), "The start date of the duration to convert to a fiscal period."))
        params.Add(New functionParameter("end_date", GetType(Date), "The end date of the duration to convert to a fiscal period."))
        params.Add(New functionParameter("context", GetType(context), "The context row of the context (from the context table)."))

        Me.parametersLists.Add(params)


    End Sub

End Class

Public Class fiscal_year
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("fiscal_year", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns the fiscal year that includes the supplied date and based on a fiscal year end date determined from the supplied fiscal year end month and day. The fiscal year end date is determined by applying the same logic as the fiscal_period (date, integer, integer) function. If a fiscal year end cannot be determined, then null is returned."
    End Sub



    Public Overrides Sub setParams()

        Dim params As New functionParameters
        params.Add(New functionParameter("contained_date", GetType(Date), "The date that is contained in the fiscal year."))
        params.Add(New functionParameter("fiscal_end_month", GetType(Integer), "The month number for the fiscal year end."))
        params.Add(New functionParameter("fiscal_end_day", GetType(Integer), "The day number for the fiscal year end."))
        Me.parametersLists.Add(params)


        ' overload1
        params = New functionParameters
        params.Add(New functionParameter("contained_date", GetType(Date), "The date that is contained in the fiscal year."))
        params.Add(New functionParameter("fiscal_year_end", GetType(Date), "The date of the fiscal year end."))
        Me.parametersLists.Add(params)

        ' overload2

        params = New functionParameters
        params.Add(New functionParameter("contained_date", GetType(Date), "The date that is contained in the fiscal year."))
        Dim p2 As New functionParameter("accession_id", GetType(Integer), "The id of the filing (accession) (from the accession table) to search")
        p2.drawFromAField = True
        p2.drawFromFieldList.Add(New drawFromField("accession_id", "accession"))
        params.Add(p2)
        Me.parametersLists.Add(params)

        ' overload3
        params = New functionParameters
        params.Add(New functionParameter("contained_date", GetType(Date), "The date that is contained in the fiscal year."))
        params.Add(New functionParameter("context", GetType(context), "The context row of the context (from the context table)."))
        Me.parametersLists.Add(params)

    End Sub

End Class



Public Class fiscal_year_end
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("fiscal_year_end", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns the month/day value reported in the accession identified by the supplied accession id. This function is used by the other fiscal period and fiscal year functions that rely on an accession to get the month/day end of the fiscal year." & vbCrLf & _
    "The fiscal year end is determined by looking for the fiscal year end month and day reported in the accession (filing) and applying the same logic as the fiscal_period (date, integer, integer) function to determine the specific fiscal year end date. The fiscal year end month and day is obtained from the dei:CurrentFiscalYearEndDate fact in the accession (filing). This fact is required by the EDGAR Filer Manual for all 10-K, 10-Q, 20-F, 40-F, 6-K, N-CSR, N-Q and NCSRS filings. If the accession (filing) does not have a dei:CurrentFiscalYearEndDate fact, the function will attempt to find the most recent available day/month end from previous filings. If the day/month end still cannot be obtained, then it will search for it in the closest subsequent filings. If the day/month end still cannot be obtained, then the fiscal period and year cannot be determined." & vbCrLf & _
    "If a fiscal year end cannot be determined, then null is returned."
    End Sub



    Public Overrides Sub setParams()

        Dim params As New functionParameters

        Dim p1 As New functionParameter("accession_id", GetType(Integer), "The id of the filing (accession) (from the accession table) to search")
        p1.drawFromAField = True
        p1.drawFromFieldList.Add(New drawFromField("accession_id", "accession"))
        params.Add(p1)
        Me.parametersLists.Add(params)



        ' overload1

        p1 = New functionParameter("filing_accession_number", GetType(String), "The filing accession number of the accession (from the accession table).")
        p1.drawFromAField = True
        p1.drawFromFieldList.Add(New drawFromField("filing_accession_number", "accession"))
        params.Add(p1)
        Me.parametersLists.Add(params)





    End Sub

End Class


Public Class fiscal_year_beginning_of_year_adjustment
    Inherits sqlFunction

    Public Sub New()
        MyBase.new("fiscal_year_beginning_of_year_adjustment", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns the adjustment that should be made to the year portion of a fiscal year. This will return either 0, which means no adjustment is needed or -1, which means the fiscal year is one year less the year of the date being processed. The adjustment is based on if the yearend falls in the first 10 days of the calendar year (Jan 1st to Jan 10th)." & vbCrLf & _
"Normally, the fiscal year is based on the calendar year in which the fiscal yearend date occurs. However, some entities may have a yearend date that floats around that end of calendar year. So in some years the year end will be a little before December 31st and in other years it will be in the beginning of January. To maintain consistency of the fiscal year, this adjustment is made if the fiscal month/day is in early January."
    End Sub

    Public Overrides Sub setParams()
        Dim params As New functionParameters
        params.Add(New functionParameter("fiscal_end_month", GetType(Integer), "The month number for the fiscal year end."))
        params.Add(New functionParameter("fiscal_end_day", GetType(Integer), "The day number for the fiscal year end."))
        Me.parametersLists.Add(params)
    End Sub


End Class

'other functions
Public Class document_type
    Inherits sqlFunction


    Public Sub New()
        MyBase.new("document_type", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns the document type of filing (accession) identified by the supplied accession id." & vbCrLf & _
"The document type is based on the dei:DocumentType fact in the accession. This is required by the EDGAR Filer Manual."
    End Sub

    Public Overrides Sub setParams()

        Dim params As New functionParameters

        Dim p1 As New functionParameter("accession_id", GetType(Integer), "The id of the filing (accession) (from the accession table)")
        p1.drawFromAField = True
        p1.drawFromFieldList.Add(New drawFromField("accession_id", "accession"))
        params.Add(p1)
        Me.parametersLists.Add(params)

    End Sub

End Class


Public Class is_base
    Inherits sqlFunction


    Public Sub New()
        MyBase.new("is_base", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns a boolean value indicating if the supplied namespace uri is part of a base taxonomy. A base taxonomy is any taxonomy listed as a standard taxonomy by the SEC (http://www.sec.gov/info/edgar/edgartaxonomies.shtml)."
    End Sub

    Public Overrides Sub setParams()

        Dim params As New functionParameters
        params.Add(New functionParameter("namespace_uri", GetType(String), "A namespace uri."))
        Me.parametersLists.Add(params)

    End Sub

End Class


Public Class is_date
    Inherits sqlFunction


    Public Sub New()
        MyBase.new("is_date", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns a boolean value indicating if the supplied string is in the format of an ISO date and is a valid date."
    End Sub

    Public Overrides Sub setParams()

        Dim params As New functionParameters
        params.Add(New functionParameter("date_string", GetType(String), "Date in string form to be checked."))
        Me.parametersLists.Add(params)

    End Sub

End Class



Public Class taxonomy_type
    Inherits sqlFunction


    Public Sub New()
        MyBase.new("taxonomy_type", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function determines the type of taxonomy the supplied namespace uri is a part of. If the namespace uri is part of a base taxonomy (see the is_base (varchar) function) then it returns the taxonomy name and version, otherwise it returns 'extension'."
    End Sub

    Public Overrides Sub setParams()

        Dim params As New functionParameters
        params.Add(New functionParameter("namespace_uri", GetType(String), "A namespace uri."))
        Me.parametersLists.Add(params)

    End Sub

End Class

Public Class ticker
    Inherits sqlFunction


    Public Sub New()
        MyBase.new("ticker", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns the ticker associated with an entity identified by the supplied entity id. The ticker is found by parsing the name of the XBRL instance file. Based on the EDGAR Filer Manual, the XBRL instance file name is comprised of a registrant’s ticker symbol or other mnemonic abbreviation. This is what is parsed from the file name. In most cases this is the common ticker for the entity, however there are cases where this is not true."
    End Sub

    Public Overrides Sub setParams()
        Dim params As New functionParameters

        Dim p1 As New functionParameter("entity_id", GetType(Integer), "The id of the entity (from the entity table).")
        p1.drawFromAField = True
        p1.drawFromFieldList.Add(New drawFromField("entity_id", "entity"))
        params.Add(p1)

        Me.parametersLists.Add(params)


    End Sub

End Class




Public Class uom
    Inherits sqlFunction


    Public Sub New()
        MyBase.new("uom", sqlTable.itemTypes.selectFunction)
        tableDescription = "This function returns a string representation of the unit of measure identified by the supplied unit id. If the unit is a monetary, the ISO currency code is returned. Otherwise, if the unit is a simple measure (no numerator or denominator) then the local name of the measure is returned. For complex units, the string is formed by taking the local name of the numerator followed by a slash followed by the local name of the denominator. This creates a simple displayable form of the unit of measure."
    End Sub

    Public Overrides Sub setParams()
        Dim params As New functionParameters

        Dim p1 As New functionParameter("unit_id", GetType(Integer), "The id of the unit of measure (from the unit table).")
        p1.drawFromAField = True
        p1.drawFromFieldList.Add(New drawFromField("unit_id", "unit"))
        params.Add(p1)

        Me.parametersLists.Add(params)


    End Sub

End Class